package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.AdminUpdownBranch;
import com.ruoyi.system.service.IAdminUpdownBranchService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 上下分管理Controller
 * 
 * @author ruoyi
 * @date 2020-11-12
 */
@RestController
@RequestMapping("/system/adminUpdown")
public class AdminUpdownBranchController extends BaseController
{
    @Autowired
    private IAdminUpdownBranchService adminUpdownBranchService;

    /**
     * 查询上下分管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:adminUpdown:list')")
    @GetMapping("/list")
    public TableDataInfo list(AdminUpdownBranch adminUpdownBranch)
    {
        startPage();
        String room = SecurityUtils.getLoginUser().getUser().getRoom();
        adminUpdownBranch.setRoom(room);
        List<AdminUpdownBranch> list = adminUpdownBranchService.selectAdminUpdownBranchList(adminUpdownBranch);
        return getDataTable(list);
    }

    /**
     * 导出上下分管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:adminUpdown:export')")
    @Log(title = "上下分管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AdminUpdownBranch adminUpdownBranch)
    {
        List<AdminUpdownBranch> list = adminUpdownBranchService.selectAdminUpdownBranchList(adminUpdownBranch);
        ExcelUtil<AdminUpdownBranch> util = new ExcelUtil<AdminUpdownBranch>(AdminUpdownBranch.class);
        return util.exportExcel(list, "adminUpdown");
    }

    /**
     * 获取上下分管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:adminUpdown:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(adminUpdownBranchService.selectAdminUpdownBranchById(id));
    }

    /**
     * 新增上下分管理
     */
    @PreAuthorize("@ss.hasPermi('system:adminUpdown:add')")
    @Log(title = "上下分管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AdminUpdownBranch adminUpdownBranch)
    {
        return toAjax(adminUpdownBranchService.insertAdminUpdownBranch(adminUpdownBranch));
    }

    /**
     * 修改上下分管理
     */
    @PreAuthorize("@ss.hasPermi('system:adminUpdown:edit')")
    @Log(title = "上下分管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AdminUpdownBranch adminUpdownBranch)
    {
        return toAjax(adminUpdownBranchService.updateAdminUpdownBranch(adminUpdownBranch));
    }

    /**
     * 删除上下分管理
     */
    @PreAuthorize("@ss.hasPermi('system:adminUpdown:remove')")
    @Log(title = "上下分管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(adminUpdownBranchService.deleteAdminUpdownBranchByIds(ids));
    }
}
